package com.hzw.saas.web.app.user.controller;

import com.hzw.saas.api.user.ICustomerPRService;
import com.hzw.saas.api.user.query.CustomerInfoUpdateQuery;
import com.hzw.saas.api.user.query.CustomerPRAddQuery;
import com.hzw.saas.common.config.annotation.SysLog;
import com.hzw.saas.common.config.exception.DefaultSaasException;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zzl
 * @since 08/23/2021
 */
@Controller
@RequiredArgsConstructor
@Slf4j
@Api(tags = "客户公关信息登记")
public class CustomerPRController {

    private final ICustomerPRService customerInfoService;

    @PostMapping("/customer/information")
    @SysLog(operation = "客户公关信息登记", mode = 3)
    @ApiOperation(value = "客户公关信息登记", notes = "客户信息登记")
    @ApiOperationSort(11)
    public ResponseEntity<Void> saveCustomerInfo(@Validated @RequestBody CustomerPRAddQuery param) {
        this.customerInfoService.save(param);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/customer/information")
    @SysLog(operation = "客户公关信息更新", mode = 3)
    @ApiOperation(value = "客户公关信息更新", notes = "客户信息更新")
    @ApiResponses({
        @ApiResponse(code = 200, message = "更新成功"),
        @ApiResponse(code = 400, message = "参数错误"),
        @ApiResponse(code = 500, message = "更新失败")
    })
    @ApiOperationSort(12)
    public ResponseEntity<Void> updateCustomerInfo(@Validated @RequestBody CustomerInfoUpdateQuery param) {
        boolean update = this.customerInfoService.update(param);
        if (update) {
            return ResponseEntity.ok().build();
        } else {
            throw DefaultSaasException.build("客户信息更新失败");
        }
    }

    @DeleteMapping("/customer/information/{pid}")
    @SysLog(operation = "客户公关信息删除", mode = 3)
    @ApiOperation(value = "客户公关信息删除", notes = "客户信息删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pid", value = "客户信息登记PID", paramType = "path", dataType = "String", required = true)
    })
    @ApiResponses({
        @ApiResponse(code = 200, message = "更新成功"),
        @ApiResponse(code = 400, message = "参数错误"),
        @ApiResponse(code = 500, message = "更新失败")
    })
    @ApiOperationSort(12)
    public ResponseEntity<Void> deleteCustomerInfo(@PathVariable String pid) {
        boolean delete = this.customerInfoService.delete(pid);
        if (delete) {
            return ResponseEntity.ok().build();
        } else {
            throw DefaultSaasException.build("客户信息删除失败");
        }
    }

}
